﻿// Example header text. Can be configured in the options.
using System;
using System.Windows.Forms;
using PharmacySystem.Unit;
using vtech_formBase.Object;
using vtech_frameWorks.Exceptions;
using vtech_system;
using vtech_system.GroupUser;
using vtech_system.Role;
using vtech_system.SystemLog;
using vtech_system.User;

namespace MainBase
{
    public partial class frmMainBase : vtech_formBase.frmMainBase
    {
        public frmMainBase()
        {
            this.InitializeComponent();
        }

        protected override void CheckPermision(string frmName)
        {
            frmObject showedForm = null;
            try
            {
                switch (frmName)
                {
                    #region Hệ thống
                    case "frmUser":
                        foreach (Form frm in Application.OpenForms)
                        {
                            if (frm is frmUser)
                            {
                                frm.MdiParent = this;
                                frm.Show();
                                frm.Activate();
                                return;
                            }
                        }
                        showedForm = new frmUser();
                        break;
                    case "frmSystemLog":
                        foreach (Form frm in Application.OpenForms)
                        {
                            if (frm is frmSystemLog)
                            {
                                frm.MdiParent = this;
                                frm.Show();
                                frm.Activate();
                                return;
                            }
                        }
                        showedForm = new frmSystemLog();
                        break;
                    case "frmRole":
                        foreach (Form frm in Application.OpenForms)
                        {
                            if (frm is frmRole)
                            {
                                frm.MdiParent = this;
                                frm.Show();
                                frm.Activate();
                                return;
                            }
                        }
                        showedForm = new frmRole();
                        break;
                    case "frmGroupUser":
                        foreach (Form frm in Application.OpenForms)
                        {
                            if (frm is frmGroupUser)
                            {
                                frm.MdiParent = this;
                                frm.Show();
                                frm.Activate();
                                return;
                            }
                        }
                        showedForm = new frmGroupUser();
                        break;
                        #endregion

                        #region Danh mục
                    case "frmUnit":
                        foreach (Form frm in Application.OpenForms)
                        {
                            if (frm is frmUnit)
                            {
                                frm.MdiParent = this;
                                frm.Show();
                                frm.Activate();
                                return;
                            }
                        }
                        showedForm = new frmUnit();
                        break;
                #endregion
                }
                if (showedForm != null)
                {
                    showedForm.MdiParent = this;
                    showedForm.Show();
                    showedForm.Activate();
                }
            }
            catch (Exception ex)
            {
                ClsInformation.Error(ex.Message);
            }
        }

        #region Button
        protected override void btnGroupUser_Click(object sender, EventArgs e)
        {
            try
            {
                this.CheckPermision(this.btnGroupUser.Tag as string);
            }
            catch (Exception ex)
            {
                ClsInformation.Information(ex.Message);
            }
        }

        protected override void btnUser_Click(object sender, System.EventArgs e)
        {
            try
            {
                this.CheckPermision(this.btnUser.Tag as string);
            }
            catch (Exception ex)
            {
                ClsInformation.Information(ex.Message);
            }
        }

        protected override void btnSystemLog_Click(object sender, EventArgs e)
        {
            try
            {
                this.CheckPermision(this.btnSystemLog.Tag as string);
            }
            catch (Exception ex)
            {
                ClsInformation.Information(ex.Message);
            }
        }

        protected override void btnChangePassword_Click(object sender, EventArgs e)
        {
            try
            {
                vtech_system.frmChangePassword frmChangePassword = new vtech_system.frmChangePassword();
                frmChangePassword.ShowDialog();
            }
            catch (Exception ex)
            {
                ClsInformation.Information(ex.Message);
            }
        }

        protected override void btnOption_Click(object sender, EventArgs e)
        {
            try
            {
                vtech_system.frmOption frmOption = new vtech_system.frmOption();
                frmOption.ShowDialog();
            }
            catch (Exception ex)
            {
                ClsInformation.Information(ex.Message);
            }
        }

        protected override void btnUnit_Click(object sender, EventArgs e)
        {
            try
            {
                this.CheckPermision(this.btnUnit.Tag as string);
            }
            catch (Exception ex)
            {
                ClsInformation.Information(ex.Message);
            }
        }

        protected override void btnRole_Click(object sender, EventArgs e)
        {
            try
            {
                this.CheckPermision(this.btnRole.Tag as string);
            }
            catch (Exception ex)
            {
                ClsInformation.Information(ex.Message);
            }
        }

        #endregion
        
        private void frmMainBase_Load(object sender, EventArgs e)
        {
            frmLogin.GetInstance().ShowDialog();
        }
        

    }
}